import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace CmtCourseChapterApi {
  /** 课程章节 */
  export interface CourseChapter {
    id?: number;
    courseId?: number; // 课程ID
    chapterTitle?: string; // 章节标题
    chapterOrder?: number; // 章节顺序
    videoUrl?: string; // 视频URL
    duration?: number; // 时长(秒)
    content?: string; // 章节内容
    createTime?: string; // 创建时间
  }

  /** 课程章节分页查询参数 */
  export interface CourseChapterPageReqVO {
    pageNo: number;
    pageSize: number;
    courseId?: number;
    chapterTitle?: string;
    createTime?: string[];
  }
}

/** 查询课程章节分页 */
export function getCourseChapterPage(params: CmtCourseChapterApi.CourseChapterPageReqVO) {
  return requestClient.get<PageResult<CmtCourseChapterApi.CourseChapter>>(
    '/cmt/course-chapter/page',
    { params },
  );
}

/** 查询课程章节详情 */
export function getCourseChapter(id: number) {
  return requestClient.get<CmtCourseChapterApi.CourseChapter>(
    `/cmt/course-chapter/get?id=${id}`,
  );
}

/** 新增课程章节 */
export function createCourseChapter(data: CmtCourseChapterApi.CourseChapter) {
  return requestClient.post('/cmt/course-chapter/create', data);
}

/** 修改课程章节 */
export function updateCourseChapter(data: CmtCourseChapterApi.CourseChapter) {
  return requestClient.put('/cmt/course-chapter/update', data);
}

/** 删除课程章节 */
export function deleteCourseChapter(id: number) {
  return requestClient.delete(`/cmt/course-chapter/delete?id=${id}`);
}

/** 批量删除课程章节 */
export function deleteCourseChapterList(ids: number[]) {
  return requestClient.delete(`/cmt/course-chapter/delete-list?ids=${ids.join(',')}`);
}

/** 导出课程章节 */
export function exportCourseChapter(params: CmtCourseChapterApi.CourseChapterPageReqVO) {
  return requestClient.download('/cmt/course-chapter/export-excel', { params });
}

/** 获取课程章节选项列表(用于下拉选择) */
export function getCourseChapterOptions() {
  return requestClient.get<PageResult<CmtCourseChapterApi.CourseChapter>>(
    '/cmt/course-chapter/page',
    { params: { pageNo: -1, pageSize: 10 } },
  );
}
